package com.anhua.controller;

import com.anhua.config.MyExcetion;
import com.anhua.pojo.StudentPropter;
import com.anhua.pojo.Teacher;
import com.anhua.pojo.UserPropter;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@Validated
public class UserContyt {
    @Autowired
//    @Qualifier("aa.bb-com.anhua.pojo.UserPropter")
    private UserPropter userPropter;
    @Autowired
//    @Qualifier("aa.bb-com.anhua.pojo.UserPropter")
    private StudentPropter studentPropter;
    @RequestMapping("/kk")
    public String getUuu(){
        String s = userPropter.getUserHome();
        System.out.println(studentPropter.getStudentName());
        System.out.println(s);
        return s+studentPropter.getStudentName();
    }
    @RequestMapping("/getTeacher")
    public String getTtt(@Validated  Teacher  teacher) throws MyExcetion {
//        JSONObject tt = (JSONObject) jsonObject.get("tt");
//        tt.get("tid");
//        Teacher teacher = (Teacher) JSONObject.toBean(tt, Teacher.class);
//
//        System.out.println(teacher.toString());
        try {
            if (1==1){
                throw new MyExcetion("1","999");
            }

        }catch (Exception e){
            if (e instanceof MyExcetion){
                throw new MyExcetion("-1","出错啦");
            }
        }
        return teacher.toString();
    }
    @GetMapping(value = "/getTeacher2")
    public String getTtt2(@NotNull(message = "不能我看")@RequestBody String   id){
        System.out.println(id);
        return id+"";
    }
}
